//
//  UIView+SafetyMargin.m
//  NineteenBook
//
//  Created by xhkj on 2021/8/2.
//  Copyright © 2021 58阅读. All rights reserved.
//

#import "UIView+SafetyMargin.h"

@implementation UIView (SafetyMargin)

//判断是否为X
- (BOOL)isIphoneX {
    CGFloat safeAreaBottom = 0;
    if (@available(iOS 11.0, *)) {
        safeAreaBottom = UIApplication.sharedApplication.keyWindow.safeAreaInsets.bottom;
    }
    return safeAreaBottom != 0;
}

- (CGFloat)statusBarHight {
    if ([self isIphoneX]) {
        return 44;
    } else {
        return 20;
    }
}

- (CGFloat)naviBarHight {
    return 44;
}

- (CGFloat)tarBarHight {
    if ([self isIphoneX]) {
        return 49 + 34;
    }
    return 49;
}

- (CGFloat)safeBottomBarHight {
    CGFloat safeAreaBottom = 0;
    if (@available(iOS 11.0, *)) {
        safeAreaBottom = UIApplication.sharedApplication.keyWindow.safeAreaInsets.bottom;
    }
    return safeAreaBottom;
}

- (CGFloat)safeTopBarHight {
    if ([self isIphoneX]) {
        return 24;
    } else {
        return 0;
    }
}


//判断是否为X
+ (BOOL)isIphoneX {
    CGFloat safeAreaBottom = 0;
    if (@available(iOS 11.0, *)) {
        safeAreaBottom = UIApplication.sharedApplication.keyWindow.safeAreaInsets.bottom;
    }
    return safeAreaBottom != 0;
}

+ (CGFloat)statusBarHight {
    if ([self isIphoneX]) {
        return 44;
    } else {
        return 20;
    }
}

+ (CGFloat)naviBarHight {
    return 44;
}

+ (CGFloat)tarBarHight {
    if ([self isIphoneX]) {
        return 49 + 34;
    }
    return 49;
}

+ (CGFloat)safeBottomBarHight {
    CGFloat safeAreaBottom = 0;
    if (@available(iOS 11.0, *)) {
        safeAreaBottom = UIApplication.sharedApplication.keyWindow.safeAreaInsets.bottom;
    }
    return safeAreaBottom;
}

+ (CGFloat)safeTopBarHight {
    if ([self isIphoneX]) {
        return 24;
    } else {
        return 0;
    }
}

//+ (CGFloat)margins {
//    return 15;
//}
//
//+ (CGFloat)mainMargins {
//    return 20;
//}

//+ (CGFloat)getAdMargin {
//    GBDeviceDisplay display = [GBDeviceInfo deviceInfo].displayInfo.display;
//    CGFloat insets = 0.0f;
//
//    if (display == GBDeviceDisplay3p5Inch) {
//        insets = 100;
//    } else if (display == GBDeviceDisplay4Inch) {
//        insets = 110;
//    } else if (display == GBDeviceDisplay4p7Inch) {
//        insets = 120;
//    } else {
//        insets = 130;
//    }
//
//    return insets;
//}

@end
